# -*- coding:utf8 -*-
import cv2 as cv

cap = cv.VideoCapture(r"videos/vtest.avi")
fgbg = cv.createBackgroundSubtractorMOG2()
kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (3, 3))

while True:
    ret, frame = cap.read()

    if ret is not True:
        break

    fgmask = fgbg.apply(frame)
    fgmask = cv.morphologyEx(fgmask, cv.MORPH_OPEN, kernel)

    cv.imshow("frame", fgmask)

    cv.waitKey()
    cv.destroyAllWindows()

cap.release()



























